package XunChunCPU.Accelerator

import chisel3._

// 布斯二位乘选择器
class BoothChooser extends Module{
    val io = IO(new Bundle{
        val X = Input(UInt(32.W))   // X根据位置移位后取低32位
        val y = Input(UInt(3.W))    // y_i, y_{i-1}, y_{i+1}
        val P = Output(UInt(32.W))   // 选择出来的结果
        val c = Output(Bool())       // 进位
    })
    when(io.y === 0.U){
        io.P := 0.U
        io.c := false.B
    }.elsewhen(io.y === 1.U){
        io.P := io.X
        io.c := false.B
    }.elsewhen(io.y === 2.U){
        io.P := io.X
        io.c := false.B
    }.elsewhen(io.y === 3.U){
        io.P := (io.X << 1)(31,0)
        io.c := false.B
    }.elsewhen(io.y === 4.U){
        io.P := ~(io.X << 1)(31,0)
        io.c := true.B
    }.elsewhen(io.y === 5.U){
        io.P := ~io.X
        io.c := true.B
    }.elsewhen(io.y === 6.U){
        io.P := ~io.X
        io.c := true.B
    }.otherwise{
        io.P := 0.U
        io.c := false.B
    }
}